<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <!--第三方lib-->
    <script src="./lib/cesiumjs/Cesium/Cesium.js"></script>
    <link href="./lib/cesiumjs/Cesium/Widgets/Widgets.css" rel="stylesheet">

    <!--      <script src="https://cesium.com/downloads/cesiumjs/releases/1.65/Build/Cesium/Cesium.js"></script>-->
    <!--  <link href="https://cesium.com/downloads/cesiumjs/releases/1.65/Build/Cesium/Widgets/widgets.css" rel="stylesheet">-->
    <script src="./lib/jquery/jquery-3.5.1.min.js"></script>
    <style>
        html,
        body,
        #cesiumContainer {
            width: 100%;
            height: 100%;
            margin: 0;
            padding: 0;
            overflow: hidden;
            background-color: #000000;
        }
    </style>
</head>

<body>
    <div id="cesiumContainer" style="width: 100%"></div>
    <script>
        Cesium.Ion.defaultAccessToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiIzZWE2NTRhOC1kYTZlLTQ0YzMtOWJiNi02ZTU2ZjlmOTg1MGMiLCJpZCI6MTQyODgsInNjb3BlcyI6WyJhc3IiLCJnYyJdLCJpYXQiOjE1NjUxNzU4MjJ9.-MyI5VpHz6X6JXRNFDQ2OPfVQHg90qO-lrBS8PrUY5w';
        var viewer = new Cesium.Viewer('cesiumContainer', {
            terrainProvider: Cesium.createWorldTerrain(),
            animation: false, //是否显示动画控件
            homeButton: false, //是否显示home键
            geocoder: false, //是否显示地名查找控件        如果设置为true，则无法查询
            baseLayerPicker: false, //是否显示图层选择控件
            timeline: false, //是否显示时间线控件
            fullscreenButton: true, //是否全屏显示
            scene3DOnly: true, //如果设置为true，则所有几何图形以3D模式绘制以节约GPU资源
            infoBox: true, //是否显示点击要素之后显示的信息
            sceneModePicker: true, //是否显示投影方式控件  三维/二维
            navigationInstructionsInitiallyVisible: false,
            navigationHelpButton: false, //是否显示帮助信息控件
            selectionIndicator: false //是否显示指示器组件

        });
        viewer._cesiumWidget._creditContainer.style.display = "none";

        var contentString = sessionStorage.spatialModel;
        // let data = window.location.href.split('?value=')[1];
        // var dataUrl =  'http://data.marsgis.cn/3dtiles/qx-shuiwu/tileset.json';
        // var content1=contentString.replace(/\\/g,"");
        // console.log(content1);
        var contentS = JSON.parse(contentString);
        // console.log(contentS);
        console.log(typeof contentS);
        var content = typeof contentS == 'string' ? JSON.parse(contentS) : contentS;
        console.log(typeof content);
        // var imagemarker= contentS.features;
        // console.log(imagemarker);
        // var content='./data/testDetail.json';
        /*    function fake_click(obj) {
              var ev = document.createEvent("MouseEvents");
              ev.initMouseEvent(
                      "click", false, false, window, 0, 0, 0, 0, 0
                      , false, false, false, false, 0, null
              );
              obj.dispatchEvent(ev);
            }

            //name-文件名；data-要保存的字符串。
            function export_raw(name, data) {
              var urlObject = window.URL || window.webkitURL || window;
              var export_blob = new Blob([data]);
              var save_link = document.createElementNS("http://www.w3.org/1999/xhtml", "a");
              save_link.href = urlObject.createObjectURL(export_blob);
              save_link.download = name;
              fake_click(save_link);
            }
            //点击按钮

            export_raw('./data/range.json', contentS);*/


        loadGeoJson(content);

        function loadGeoJson(content) {
            var data = window.viewer.dataSources.add(Cesium.GeoJsonDataSource.load(content, {
                // stroke: Cesium.Color.HOTPINK,//颜色样式渲染
                // fill: Cesium.Color.PINK,
                // strokeWidth: 3,
                // markerSymbol: './gis/data/geojson/render.png'
                // markerSymbol: imagemarker
            }));
            window.viewer.zoomTo(data);

            //Seed the random number generator for repeatable results.

            /*      Cesium.Math.setRandomNumberSeed(0);
                  var promise=Cesium.GeoJsonDataSource.load('content');
                  promise.then(function(dataSource) {
                    viewer.dataSources.add(dataSource);
                    var entities = dataSource.entities.values;
                    var colorHash = {};
                    for (var i = 0; i < entities.length; i++) {
                      var entity = entities[i];
                      var name = entity.name;
                      var color = colorHash[name];
                      if (!color) {
                        color = Cesium.Color.fromRandom({
                          alpha : 1.0
                        });
                        colorHash[name] = color;
                      }
                      entity.polygon.material = color;
                      entity.polygon.outline = false;
                      entity.polygon.extrudedHeight =5000.0;
                    }
                  });
                  viewer.flyTo(promise);*/


        }
    </script>
</body>

</html>